package com.ming.springbillmanager.config;

import com.ming.springbillmanager.interceptor.LoginHanderInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @project_name: spring2
 * @description:
 * @author: arvin w ming
 * @create: 2022-09-08 08:20
 */

@Configuration
public class MySpringMvcConfig {


    //register 用这个对象来实现跳转[匿名内部类]

    @Bean
    public WebMvcConfigurer webMvcConfigurer(){
        return new WebMvcConfigurer() {



            //注册【跳转】
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
               registry.addViewController("/").setViewName("main/login");
               registry.addViewController("/index.html").setViewName("main/login");
               registry.addViewController("/main.html").setViewName("main/index");
            }

            //注册【拦截器】
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
               registry.addInterceptor(new LoginHanderInterceptor())
                       .addPathPatterns("/**")
                       .excludePathPatterns("/","/index.html","/login")
                       .excludePathPatterns("/css/*","/img/*","/js/*");
            }


        };
    }

}
